package com.cloud.salon.client.business.repository;

import com.cloud.salon.common.base.entity.business.Preference;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.Transient;
import java.util.List;

/*
 * @Description 优惠仓库接口
 * @Author wolf--LZH
 * @CreateDate 2019/5/17 0017 下午 4:25
 */
public interface PreferentialRepository extends JpaRepository<Preference, Integer> {

    List<Preference> findByAccountId(Integer accountId);

    List<Preference> findByAccountIdAndItemId(Integer accountId, Integer itemId);

    List<Preference> findByAccountIdAndIdIn(Integer accountId, List<Integer> preferenceIdList);

    @Modifying
    @Transactional
    @Query(value = "update Preference set times = times + ?2 where id = ?1 ")
    Integer setTimes(Integer preferenceId, Integer timesDelta);
}
